package com.wu.pojo.bean;

import com.wu.pojo.po.paperPo.Question;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.*;
import lombok.experimental.Accessors;
import net.sf.json.JSONArray;
import org.hibernate.validator.constraints.Range;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

@Data
@ApiModel("问卷题目bean")
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class PaperQuestionAddBean implements Serializable {

    @ApiModelProperty("题目名称")
    @NotNull(message = "题目不能为空")
    @Size(min = 1, max = 128, message = "题目应该是1到128个字符")
    private String questionTitle;

    @ApiModelProperty("题目类型")
    @Range(min=1, max=3)
    private String questionType;

    @ApiModelProperty("题目序号")
    private int questionNo;

    @ApiModelProperty("题目选项")
    private List<Object> questionOption;

    public Question questionInit(){
        Question question = new Question();
        question.setQuestionType(questionType).setQuestionTitle(questionTitle)
                .setQuestionNo(questionNo)
                .setQuestionOption(JSONArray.fromObject(questionOption).toString())
                .setCreateTime(new Date());
        return question;
    }
}
